load("@rules_cc//cc:defs.bzl", "cc_binary")
load("//bazel:transitions.bzl", "platform_transition_binary")

package(default_visibility = ["//visibility:public"])

# Disabled targets need the user to supply a sysroot in `flake.nix` first.

# platform_transition_binary(
#     name = "cc_binary_aarch64-apple-darwin",
#     binary = ":cc_binary",
#     target_platform = "//bazel/platforms:aarch64-apple-darwin",
# )

# platform_transition_binary(
#     name = "cc_binary_aarch64-apple-ios",
#     binary = ":cc_binary",
#     target_platform = "//bazel/platforms:aarch64-apple-ios",
# )

platform_transition_binary(
    name = "cc_binary_aarch64-linux-android",
    binary = ":cc_binary",
    target_platform = "//bazel/platforms:aarch64-linux-android",
)

platform_transition_binary(
    name = "cc_binary_aarch64-unknown-linux-gnu",
    binary = ":cc_binary",
    target_platform = "//bazel/platforms:aarch64-unknown-linux-gnu",
)

platform_transition_binary(
    name = "cc_binary_wasm32-unknown-unknown",
    binary = ":cc_binary",
    target_platform = "//bazel/platforms:wasm32-unknown-unknown",
)

platform_transition_binary(
    name = "cc_binary_wasm32-wasi",
    binary = ":cc_binary",
    target_platform = "//bazel/platforms:wasm32-wasi",
)

# platform_transition_binary(
#     name = "cc_binary_x86_64-apple-darwin",
#     binary = ":cc_binary",
#     target_platform = "//bazel/platforms:x86_64-apple-darwin",
# )

# platform_transition_binary(
#     name = "cc_binary_x86_64-pc-windows-msvc",
#     binary = ":cc_binary",
#     target_platform = "//bazel/platforms:x86_64-pc-windows-msvc",
# )

platform_transition_binary(
    name = "cc_binary_x86_64-unknown-linux-gnu",
    binary = ":cc_binary",
    target_platform = "//bazel/platforms:x86_64-unknown-linux-gnu",
)

platform_transition_binary(
    name = "cc_binary_x86_64-unknown-nixos-gnu",
    binary = ":cc_binary",
    target_platform = "//bazel/platforms:x86_64-unknown-nixos-gnu",
)

cc_binary(
    name = "cc_binary",
    srcs = select({
        # See comment in `cc_binary_wasm32.cc`.
        "@platforms//os:none": ["cc_binary_wasm32-unknown-unknown.cc"],
        "//conditions:default": ["cc_binary.cc"],
    }),
    tags = ["platform_missing"],
    deps = [
        "//cc_library",
        "//rust_library:rust_library_cc",
    ],
)
